package com.hu.video.service.impl;

import com.hu.video.entity.SocialVideoLike;
import com.hu.video.mapper.SocialVideoLikeMapper;
import com.hu.video.service.ISocialVideoLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;

@Service
public class SocialVideoLikeServiceImpl implements ISocialVideoLikeService {
    @Autowired
    private SocialVideoLikeMapper likeMapper;

    @Override
    public boolean likeVideo(Long videoId, Long userId) {
        if (likeMapper.selectByVideoAndUser(videoId, userId) != null) return false;
        SocialVideoLike like = new SocialVideoLike();
        like.setVideoId(videoId);
        like.setUserId(userId);
        like.setCreatedAt(new Date());
        return likeMapper.insertLike(like) > 0;
    }

    @Override
    public boolean unlikeVideo(Long videoId, Long userId) {
        return likeMapper.deleteLike(videoId, userId) > 0;
    }

    @Override
    public int getLikeCount(Long videoId) {
        return likeMapper.countLikes(videoId);
    }

    @Override
    public boolean isLiked(Long videoId, Long userId) {
        return likeMapper.selectByVideoAndUser(videoId, userId) != null;
    }
} 